#include "generalsetstyle.h"

void GeneralSetButtonStyle(QPushButton *button,const QString filename,int iconsize,
                          QString tooltip)
{

    button->setFixedSize(iconsize, iconsize);
    button->setIcon(QIcon(filename));
    button->setIconSize(QSize(button->width() - 5, button->height() - 5));
    // 设置背景颜色为透明，不过好像在linux上没法用,背景调成黑色了
    // 悬停变化
    button->setCursor(Qt::PointingHandCursor);
    button->setStyleSheet(R"(
                            QPushButton
                            {

                                border-radius: 10px;
                                border: none;
                            }
                            QPushButton:hover
                            {
                                background: rgba(0,0,0,50);/*悬停时背景颜色*/
                            }
                        )");
    button->setToolTipDuration(2000); // 2秒后消失
    //弹窗提示
    button->setToolTip(tooltip);

    // 下面是动画
    // 按钮点击动画添加
    QAbstractButton::connect(button, &QPushButton::pressed, [=]() {
        QPropertyAnimation *anim = new QPropertyAnimation(button, "geometry");
        anim->setDuration(10);//动画持续时间
        anim->setStartValue(button->geometry());
        anim->setEndValue(button->geometry().adjusted(-1, -1, -1, -1));
        anim->start(QAbstractAnimation::DeleteWhenStopped);
    });
    QAbstractAnimation::connect(button, &QPushButton::released, [=]() {
        QPropertyAnimation *anim = new QPropertyAnimation(button, "geometry");
        anim->setDuration(10);//动画持续时间
        anim->setStartValue(button->geometry());
        anim->setEndValue(button->geometry().adjusted(1, 1, 1, 1));
        anim->start(QAbstractAnimation::DeleteWhenStopped);
    });
}
